﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.IO;


namespace Idlesoft.ShellAnywhereLanguage
{
	public enum LinkType : int
	{
		Undef,
		Exe,
		Lnk,
		File,
		Folder,
		Action
	}

	public class Link : Target, IXmlSerializable
	{
		#region ctors

		public Link(string value) : base(value) { }
		//public Link(string path, string value = null) : base(System.IO.Path.GetFileName(path) ) //base(System.IO.Path.GetFileName(path), null)
		//{
		//    Path = path;
		//    Position = new Point();
		//    Size = new Point();
		//    if (value != null) //if value of 'value' passed in is not null, reassign the value of 'Value' in Param
		//        Value = value;
		//}
		//public Link(string path, string arguments, string value = null)
		//    : this(path, value)
		//{
		//    Arguments = arguments;
		//}
		//public Link(string path, string arguments, string description, string value = null)
		//    : this(path, arguments, value)
		//{
		//    Description = description;
		//}
		//public Link(string path, string arguments, string description, Point position, Point size, string value = null)
		//    : this(path, arguments, description, value)
		//{
		//    Position = position;
		//    Size = size;
		//}
		#endregion ctors

		#region props
		[XmlAttribute]
		public string Path { get; set; }
		[XmlAttribute]
		public string Arguments { get; set; }
		[XmlAttribute]
		public string Description { get; set; }
		[XmlAttribute]
		public Point Position { get; set; }
		[XmlAttribute]
		public Point Size { get; set; }
		[XmlIgnore]
		public string Ext { get { return System.IO.Path.GetExtension(Path); } }
		[XmlIgnore]
		public LinkType TargetType
		{
			get
			{
				LinkType type = LinkType.Undef;
				string ext = Ext;
				if (ext == ".exe")
					type = LinkType.Exe;
				else if (ext == ".lnk")
					type = LinkType.Lnk;
				else if (Directory.Exists(Path))
					type = LinkType.Folder;
				else if (File.Exists(Path))
					type = LinkType.File;
				return type;
			}
		}
		#endregion props

		#region methods
		public XmlSchema GetSchema() { return null; }
		public XmlSerializer GetPointSerializer() { return new XmlSerializer(typeof(Point)); }
		public void ReadXml(XmlReader reader)
		{
			reader.MoveToContent();
			Value = reader["Value"];
			Path = reader["Path"];
			Arguments = reader["Arguments"];
			Description = reader["Description"];
			Position = new Point(reader["Position"]);
			Size = new Point(reader["Size"]);
		}

		public void WriteXml(XmlWriter writer)
		{
		}
		public override string ToString()
		{
			return base.ToString();
		}
		#endregion methods
	}
}
